package com.alan.mr.weibo;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 *  统计tf, n
 *  TF:当前关键字在该天微博内容中出现的次数
 *  N:微博的总条数。
 * Created by Alan on 2017/10/2.
 */
public class FirstReducer extends Reducer<Text,IntWritable,Text,IntWritable>{

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable i: values) {
            sum += i.get();
        }
        if(key.equals(new Text("count"))){
            System.out.println(key.toString() + "---"+sum);
        }
        context.write(key,new IntWritable(sum));
    }
}
